<?php
apf_require_class('APF_Controller');
apf_require_class('Solr_Bll_AppBiz');
apf_require_class('Solr_Bll_IdxRequestBiz');
apf_require_class('Solr_Bll_ReportHostBiz');
class Report_CreateHostDataController extends APF_Controller {

    public static function build_uri() {
        $base_domain = APF::get_instance()->get_config("base_domain");
        $schema = APF::get_instance()->get_request()->is_secure() ? "https" : "http";
        $url = "{$schema}://{$base_domain}/report/createhostdata/";
        return $url;
    }

    public function handle_request() {
        $request = APF::get_instance()->get_request();
        $params = $request->get_parameters();
        if($params['datei']){
            $date=date('Y-m-d',strtotime($params['datei']));
        }else{
            $date=date('Y-m-d');
        }

        set_time_limit(0);
        $idx_port_list=Solr_Bll_AppBiz::get_instance()->get_idx_port_list();
        $idx_request_biz=Solr_Bll_IdxRequestBiz::get_instance();
        foreach($idx_port_list as $v){
            $stat=$idx_request_biz->get_request_stat($v['hostname'],$v['port'],$date);
            $attr['hostname_id']=$v['host_id'];
            $attr['datei']=$date;
            $attr['port']=$v['port'];
            $attr['count_min']=floatval($stat['count_min']);
            $attr['slow_min']=floatval($stat['slow_min']);
            $attr['max_count_min']=floatval($stat['max_count_min']);
            Solr_Bll_ReportHostBiz::get_instance()->insert_report_host($attr);
        }
        echo 1;
        return false;
    }

}